package com.nju.crawler.controller;

import com.nju.crawler.service.GraphxService;
import com.nju.crawler.service.QueryProProportionService;
import com.nju.crawler.service.QueryTopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @authorliyunfei
 * @date2022/11/19
 **/
@RestController
public class GithubRestController {
    @Autowired
    QueryTopService queryTopService;
    @Autowired
    QueryProProportionService queryProProportionService;
    @Autowired
    GraphxService graphxService;

    @GetMapping("/getTop")
    @CrossOrigin
    // 序列化问题考虑--暂时不考虑
    public Map<String, Map> getTop(){
        /*
        {
          starTop:{
              nameList:[],
              valList:[]
          }

         forkTop:{
              nameList:[],
              valList:[]
          }

         }
         */
        return queryTopService.queryTop();
    }
    @GetMapping("/getProportion")
    @CrossOrigin
    // 序列化问题考虑--暂时不考虑
    public Map<String, Map> getProportion(){
        return queryProProportionService.queryProportion();
    }


    @GetMapping("/getUserRepoGraphx")
    @CrossOrigin
    public Map<String, List<Map<String,Object>>>  getUserRepoGraphx(){
           return graphxService.getUserRepoGraph();
    }

    @PostMapping("/updateUserRepoGraphx")
    @CrossOrigin
    public Map<String,Map> updateUserRepoGraphx(){
           return null;
    }

    /**
     * 前端获取用户-用户图数据
     */
    @GetMapping("/getUserGraphx")
    @CrossOrigin
    public Map<String, List<Map<String,Object>>> getUserGraphx(){
        return graphxService.getUserGraph();
    }

    @PostMapping("/updateUserGraphx")
    @CrossOrigin
    public boolean updateUserGraphx(Map<String, List<Map<String,Object>>> newGraph){
           return graphxService.updateUserGraph(newGraph);
    }

}
